﻿Public Class frmPrincipal
    Public ayuda() As String

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click, CrearImagenToolStripMenuItem.Click
        Dim opd As New OpenFileDialog
        opd.Filter = "Imagenes|*.jpg|Todos (*.*)|*.*"
        opd.Multiselect = True
        Dim res As DialogResult = opd.ShowDialog
        If res = Windows.Forms.DialogResult.Cancel Then Exit Sub
        ayuda = opd.FileNames


        Dim var As Boolean = True
        For i As Integer = 0 To ayuda.Length - 1 Step 1
            var = True
            For j As Integer = 0 To My.Application.OpenForms.Count - 1

                If My.Application.OpenForms(j).GetType.Name = "frmimagen" Then
                    If TryCast(My.Application.OpenForms(j), frmimagen).miFoto._rutaCompleta = ayuda(i) Then
                        MessageBox.Show("La foto" & TryCast(My.Application.OpenForms(j), frmimagen).miFoto.nombreImagen & " ya se encuentra abierta")
                        var = False
                    End If
                End If
            Next
            If var Then
                Dim foto = New Imagen
                foto._rutaCompleta = ayuda(i)
                Dim frm As New frmimagen
                frm.miFoto = foto
                frm.PictureBox1.ImageLocation = foto._rutaCompleta
                frm.Show()
            End If
           
        Next


    End Sub


    Private Sub Salir_Click(sender As System.Object, e As System.EventArgs) Handles Salir.Click
        Me.Close()
    End Sub


    Private Sub SalirToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SalirToolStripMenuItem.Click, Salir.Click
        Me.Close()
    End Sub

    Private Sub AcercaDeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AcercaDeToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub

    Private Sub DescargarImagenesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles DescargarImagenesToolStripMenuItem.Click, ToolStripButton2.Click
        For i = My.Application.OpenForms.Count - 1 To 0 Step -1
            If My.Application.OpenForms(i).GetType.Name = "frmimagen" Then
                My.Application.OpenForms(i).Close()
            End If
        Next
    End Sub
End Class
